﻿using CPPEI.Coolzon.Designer.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DT = CPPEI.Coolzon.Designtime.Metadata;

namespace CPPEI.Coolzon.Designtime
{
    public class DesignerImageResPool : IImageResPool
    {
        /// <summary>
        /// 获取所有的图片
        /// </summary>
        /// <returns>图片绝对地址数组</returns>
        public ImageRes[] GetImages()
        {
            List<ImageRes> pathList = new List<ImageRes>();

            DT.Solution dtSolution = UIContext.Current.CurrentSolution;

            for(int index = 0; index < dtSolution.Resources.Count;index++)
            {
                if(dtSolution.Resources[index].Type == DT.ResourceType.Image)
                {
                    string path = DT.LocalStorage.GetResourceFileAbsolutePath(UIContext.Current.LocalWorkSpace.LocalPath, dtSolution.ID, dtSolution.Resources[index].Id, dtSolution.Resources[index].Extension);

                    ImageRes res = new ImageRes(dtSolution.Resources[index].FileName, path);

                    pathList.Add(res);
                }
            }
            return pathList.ToArray();
        }

        public ImageRes[] GetVideos()
        {
            List<ImageRes> pathList = new List<ImageRes>();

            DT.Solution dtSolution = UIContext.Current.CurrentSolution;

            for (int index = 0; index < dtSolution.Resources.Count; index++)
            {
                if (dtSolution.Resources[index].Type == DT.ResourceType.Video)
                {
                    string path = DT.LocalStorage.GetResourceFileAbsolutePath(UIContext.Current.LocalWorkSpace.LocalPath, dtSolution.ID, dtSolution.Resources[index].Id, dtSolution.Resources[index].Extension);

                    ImageRes res = new ImageRes(dtSolution.Resources[index].FileName, path);

                    pathList.Add(res);
                }
            }
            return pathList.ToArray();
        }

        public ImageRes[] GetScripts()
        {
            List<ImageRes> pathList = new List<ImageRes>();

            DT.Solution dtSolution = UIContext.Current.CurrentSolution;

            for (int index = 0; index < dtSolution.Resources.Count; index++)
            {
                if (dtSolution.Resources[index].Type == DT.ResourceType.Script)
                {
                    string path = DT.LocalStorage.GetResourceFileAbsolutePath(UIContext.Current.LocalWorkSpace.LocalPath, dtSolution.ID, dtSolution.Resources[index].Id, dtSolution.Resources[index].Extension);

                    ImageRes res = new ImageRes(dtSolution.Resources[index].FileName, path);

                    pathList.Add(res);
                }
            }
            return pathList.ToArray();
        }

        public ImageRes[] GetTxt()
        {
            List<ImageRes> pathList = new List<ImageRes>();

            DT.Solution dtSolution = UIContext.Current.CurrentSolution;

            for (int index = 0; index < dtSolution.Resources.Count; index++)
            {
                if (dtSolution.Resources[index].Type == DT.ResourceType.Text)
                {
                    string path = DT.LocalStorage.GetResourceFileAbsolutePath(UIContext.Current.LocalWorkSpace.LocalPath, dtSolution.ID, dtSolution.Resources[index].Id, dtSolution.Resources[index].Extension);

                    ImageRes res = new ImageRes(dtSolution.Resources[index].FileName, path);

                    pathList.Add(res);
                }
            }
            return pathList.ToArray();
        }
    }
}
